//
//  TabbarController.m
//  ViewControllerTransition
//
//  Created by chavez on 2017/6/28.
//  Copyright © 2017年 chavez. All rights reserved.
//

#import "TabbarController.h"
#import "NavigationController.h"
#import "OrderBaseControl.h"
#import "ProductViewController.h"
#import "MJ_OwnerOperationController.h"
#import "MJ_TaskViewController.h"
#define Class(className) NSClassFromString(@#className)


@interface TabbarController ()<UITabBarControllerDelegate>

@end

@implementation TabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    
    [self addChildVCWithClass:Class(MJ_TaskViewController) title:@"任务" imageName:@"task" selectImage:@"task_Pre"];
    [self addChildVCWithClass:Class(ProductViewController) title:@"项目" imageName:@"project" selectImage:@"project_pre"];
    
    //如果为owner，可以查看运营模块
    switch (CurrentUserType) {
        case 1:
            [self addChildVCWithClass:Class(MJ_OwnerOperationController) title:@"运营" imageName:@"运营" selectImage:@"运营_pre"];
            break;
        default:
            break;
    }
}

/** 添加自控制器
 * @param class 控制器类
 * @param title tabBarItem.title
 * @param imageName tabBarItem.image
 */
- (void)addChildVCWithClass:(Class)class title:(NSString *)title imageName:(NSString *)imageName selectImage:(NSString *)selectImage{
    UIViewController *viewController = [[class alloc] init];
    NavigationController *navigationController = [[NavigationController alloc] initWithRootViewController:viewController];
    navigationController.tabBarItem.title = title;
    navigationController.tabBarItem.image = [UIImage imageNamed:imageName];
    navigationController.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];
    [self addChildViewController:navigationController];
}


#pragma mark - UITabBarController protocol methods
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    
    if ([viewController isKindOfClass:[NavigationController class]]) {
        
        NavigationController *navigationController = (NavigationController *)viewController;
        UIViewController *_viewController = navigationController.viewControllers.firstObject;
    
        if ([_viewController isKindOfClass:[ProductViewController class]]) {
            shareData.atProjectPart = YES;
        } else {
            shareData.atProjectPart = NO;
        }
    }
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
}




@end
